package model;

import util.AppUtil;

import com.jfinal.plugin.activerecord.Model;

import constant.Msg;

public class MomentComment extends Model<MomentComment>{

	private static final long serialVersionUID = 1L;
	public static final MomentComment dao=new MomentComment();
	public static final String showCommentsSQL="select * from moment_comments where moment_id = ?";
	//查看全部评论回复
	public String showComments(Integer moment_id){
		try{
			return AppUtil.modelToJson(dao.find(showCommentsSQL,moment_id));
		}catch(Exception e){
			e.printStackTrace();
			return Msg.ERROR_UNKNOWN;
		}
		
	}
	
	//评论文章
	public String addComment(MomentComment comment) {
		try {
			dao.set("moment_id", comment.get("moment_id"))
			.set("user_id",comment.get("user_id"))
			.set("content", comment.get("content"))
			.set("create_time", System.currentTimeMillis()/1000).save();
			return Msg.SUCCESS_EXECUTE;
		} catch (Exception e) {
			e.printStackTrace();
			return Msg.ERROR_UNKNOWN;
		} 		
	}	
	//删除评论
	public String deleteComment(String commentId){
		try {
			dao.deleteById(commentId);
			return Msg.SUCCESS_EXECUTE;
		} catch (Exception e) {
			e.printStackTrace();
			return Msg.SUCCESS_EXECUTE;
		}
	}
}
